<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/templates/ui.xhtml">

<ui:define name="head">
    <title>查询发票</title>
    <script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="js/yxfunc.js"></script>
    <style type="text/css">
        .backinv {
            color: red;
        }

        .col-label2 {
            width: 150px;
            font-size: 12px !important;
            text-align: right;
            font-weight: bold;
        }

        .col-input2 {
            font-size: 12px !important;
            text-align: left;
            font-weight: bold;
        }
    </style>
</ui:define>
<ui:define name="content">
<h:form id="inputform" enctype="multipart/form-data">
<p:messages id="msgs" showSummary="true"/>
<p:panel>
    <h:panelGrid id="dataPanel" columns="2" style="width: 100%;">
        <h:panelGrid columns="4" cellpadding="0" cellspacing="5" border="0" style="width:80%;"
                     columnClasses="col-label2, col-input2, col-label2, col-input2">

            <h:outputLabel value="发票代码:"/>
            <p:inputText id="invcode" value="#{commonAction.invInfoQryCond.invCode}"/>

            <h:outputLabel value="发票号码:"/>
            <p:inputText id="invno" value="#{commonAction.invInfoQryCond.invNo}"/>

            <h:outputLabel value="退票发票代码:"/>
            <p:inputText id="fadeinvcode" value="#{commonAction.invInfoQryCond.fadeInvCode}"/>

            <h:outputLabel value="退票发票号码:"/>
            <p:inputText id="fadeinvno" value="#{commonAction.invInfoQryCond.fadeInvNo}"/>

            <h:outputLabel value="客户名称:"/>
            <p:inputText id="custname" value="#{commonAction.invInfoQryCond.custName}"/>

            <h:outputLabel value="开票类型:"/>
            <p:selectOneMenu id="invtype" value="#{commonAction.invInfoQryCond.invType}">
                <f:selectItem itemLabel="" itemValue=""/>
                <f:selectItem itemLabel="正常票" itemValue="1"/>
                <f:selectItem itemLabel="退回票" itemValue="2"/>
            </p:selectOneMenu>

            <h:outputLabel value="开票日期起:"/>
            <p:inputText id="txndate1" size="20" value="#{commonAction.invInfoQryCond.invDateSta}"
                         onfocus="WdatePicker({dateFmt:'yyyyMMdd',maxDate:'#F{$dp.$D(\'inputform:txndate2\')}'})"/>

            <h:outputLabel value="开票日期止:"/>
            <p:inputText id="txndate2" size="20" value="#{commonAction.invInfoQryCond.invDateEnd}"
                         onfocus="WdatePicker({dateFmt:'yyyyMMdd',minDate:'#F{$dp.$D(\'inputform:txndate1\')}'})"/>


        </h:panelGrid>
        <h:panelGrid id="qbtn" columns="1" style="text-align:center;" width="20%">
            <p:commandButton style="width:120px;" value="检索"
                             actionListener="#{commonAction.onQueryInvInfo}" update="dtsuccess">
            </p:commandButton>

            <p:commandButton style="width:120px;" value="导出发票明细" ajax="false"
                             actionListener="#{commonAction.exportInvData}">
            </p:commandButton>

            <p:commandButton style="width:120px;" value="正常票抄税" update="msgs"
                             onclick="return affirmOper();" actionListener="#{commonAction.invalidInvInfo('1')}">
            </p:commandButton>

            <p:commandButton style="width:120px;" value="退回票抄税" update="msgs"
                             onclick="return affirmOper();" actionListener="#{commonAction.invalidInvInfo('2')}">
            </p:commandButton>
        </h:panelGrid>
    </h:panelGrid>
</p:panel>


<p:ajaxStatus style="height:18px;text-align:center">
    <f:facet name="start">
        <h:graphicImage value="images/ajaxloadingbar.gif"/>
    </f:facet>
    <f:facet name="complete">
        <h:outputText value=""/>
    </f:facet>
</p:ajaxStatus>
<p:separator/>
<p:contextMenu for="dtsuccess">
    <p:menuitem value="查看发票明细" icon="ui-icon-search"
                actionListener="#{commonAction.showInvItem}"
                update="invItemtb" oncomplete="showInvItem.show()">
    </p:menuitem>

    <p:menuitem value="退票" icon="ui-icon-plus" update="msgs"
                actionListener="#{commonAction.printBackInv}">
    </p:menuitem>
</p:contextMenu>
<p:dataTable id="dtsuccess" height="200" value="#{commonAction.invInvInfoList}"
             var="invInforecord" rowKey="#{invInforecord.pkid}"
             selection="#{commonAction.selectedInvInvInfo}" selectionMode="single"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true" paginatorPosition="bottom" rows="15" rowsPerPageTemplate="100,50,15,10,5"
             emptyMessage="数据记录为空..." rowStyleClass="#{invInforecord.invType eq '2' ? 'backinv':''}">
    <f:facet name="header">
        发票信息
    </f:facet>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="发票代码"/>
        </f:facet>
        <h:outputText value="#{invInforecord.invCode}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="发票号码"/>
        </f:facet>
        <h:outputText value="#{invInforecord.invNo}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="开票日期"/>
        </f:facet>
        <h:outputText value="#{invInforecord.invDate}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="合计金额"/>
        </f:facet>
        <h:outputText value="#{invInforecord.priceSum}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="机器编码"/>
        </f:facet>
        <h:outputText value="#{invInforecord.macCode}"/>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="税控码"/>
        </f:facet>
        <h:outputText value="#{invInforecord.taxCode}"/>
    </p:column>
    <p:column style="text-align:left">
        <f:facet name="header">
            <h:outputText value="客户名称"/>
        </f:facet>
        <h:outputText value="#{invInforecord.custName}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="退票发票代码"/>
        </f:facet>
        <h:outputText value="#{invInforecord.fadeInvCode}"/>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="退票发票号码"/>
        </f:facet>
        <h:outputText value="#{invInforecord.fadeInvNo}"/>
    </p:column>
    <p:column style="text-align:left">
        <f:facet name="header">
            <h:outputText value="备注"/>
        </f:facet>
        <h:outputText value="#{invInforecord.remark}"/>
    </p:column>
    <f:facet name="footer">
        <h:commandLink>
            <h:outputText value="[导出数据]"/>
            <p:dataExporter type="xls" target="dtsuccess" fileName="invoiceInfo"/>
        </h:commandLink>
    </f:facet>
</p:dataTable>

<p:dialog id="showInvItem" widgetVar="showInvItem" header="发票详情" modal="true" showEffect="drop"
          hideEffect="drop" width="900" height="400">
    <p:outputLabel style="font-size: 12px !important;font-weight: bold;color: grey;"
                   value="项目名称：01-贷款 02-贴现 03-个人 04-顺延"/>
    <p:dataTable id="invItemtb" height="100%" value="#{commonAction.invItemList}"
                 var="invItemrecord"
                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 paginator="true" paginatorPosition="bottom" rows="15" rowsPerPageTemplate="100,50,15,10,5"
                 emptyMessage="数据记录为空...">
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="发票代码"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.invCode}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="发票号码"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.invNo}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="客户名称"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.custName}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="项目编号"/>
            </f:facet>
            <h:outputText
                    value="#{invItemrecord.itemCode}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="数量"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.num}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="单价"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.price}">
                <f:convertNumber type="number" pattern="#,###,###,###,##0.00"/>
            </h:outputText>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="金额"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.cash}">
                <f:convertNumber type="number" pattern="#,###,###,###,##0.00"/>
            </h:outputText>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="摘要"/>
            </f:facet>
            <h:outputText value="#{invItemrecord.summary}"/>
        </p:column>

        <f:facet name="footer">
            <h:commandLink>
                <h:outputText value="[导出数据]"/>
                <p:dataExporter type="xls" target="invItemtb" fileName="invItems"/>
            </h:commandLink>
        </f:facet>
    </p:dataTable>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>